<?php
use Yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\widgets\LinkPager;
use yii\helpers\Url;
$this->title = '资讯标签管理';
?>
<div class="container">
    <div class="row">
      
        <?php echo $this->render('_leftnav'); ?>
        <div class="col-md-10">
          <div class="page-header clearfix">
            <h1 class="pull-left">标签管理</h1>
            <div class="pull-right">

                                                                      <a class="btn btn-success btn-sm" data-url="/admin/article/category/create" data-toggle="modal" data-target="#addlable">添加标签</a>

                                                
            </div>
          </div>         
<table class="table table-hover" id="category-table">
  <thead>
    <tr>
      <th width="45%">标签名</th>
      <th width="20%">添加时间</th>
      <th width="10%">显示序号</th>
      <th width="20%">操作</th>
    </tr>
  </thead>
  <tbody>
      <?php foreach($model as $k=>$lable){?>
  			<tr id="category-tr-1">
		  <td><?php echo $lable['artlable_name']?></td>
		  <td><?php echo date('Y-m-d H:i:s',$lable['artlable_addtime'])?></td>
		  <td><?php echo $lable['artlable_sort']?></td>
		  <td>
		    <a href="javascript:;" class="btn btn-default btn-sm ediltlable" data-url="/admin/article/category/1/edit" data-toggle="modal" data-target="#ediltlable" name="<?php echo $lable['artlable_id'];?>"><i class="glyphicon glyphicon-edit"></i> 编辑</a>
		  	<a href="javascript:;" class="btn btn-default btn-sm deletetype" type="<?php echo $lable['artlable_id'];?>"><i class="glyphicon glyphicon-trash"></i> 删除</a>	      	
	      			  </td>
		</tr>
			<?php }?>
	</tbody></table>
        </div>
<?php echo LinkPager::widget([
        'pagination' => $pages,
        'prevPageLabel'=>'上一页',
        'nextPageLabel'=>'下一页',
      ]);?>


          </div>
  </div>
    <div id="ediltlable" class="modal fade"></div>
<!-- 标签添加 -->
<div class="modal fade" id="addlable">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title">添加字段</h4>
      </div>
      
      <?php $form = ActiveForm::begin(['options'=>['class'=>'form-horizontal'],'action' => ['operate/addlabel'],'method'=>'post',]); ?>
      <div class="modal-body">
            
            <div class="form-group "> 
             <label class="col-md-4 control-label" for="field_title">标签名</label>
              <div class="col-md-6 controls">
              <input data-explain="" data-widget-cid="widget-1" name="artlable_name" id="field_title" class="form-control" type="text">
              <div class="help-block" style="display:none;"></div></div>
            </div>
            <div class="form-group "> 
             <label class="col-md-4 control-label" for="field_seq">显示序号</label>
              <div class="col-md-6 controls">
              <input data-explain="" data-widget-cid="widget-2" name="artlable_sort" id="field_seq" class="form-control" value="1" type="text">
              <div class="help-block" style="display:none;"></div></div>
            </div>
       </div> 
      
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="submit" class="btn btn-primary" id="add-btn">保存</button>
      </div>
      <?php ActiveForm::end(); ?>
    </div>
  </div>
</div>


<script>
  //标签编辑
  $(".ediltlable").click(function(){
        var artlable_id=$(this).attr("name");
        $.ajax({
            type: "POST",
            url: "<?= Url::to(['operate/editlable']);?>",
            data: "artlable_id="+artlable_id,
            success: function(msg){
               $("#ediltlable").html(msg)
            }
        });
    })
  //标签删除
  $(".deletetype").click(function(){
    var artlable_id = $(this).attr('type');
    $.ajax({
        type: "POST",
        url: "<?= Url::to(['operate/dellable']);?>",
        data: "artlable_id="+artlable_id,
        success:function(msg){
          var msg=JSON.parse(msg);
          if(msg.code==1){
            alert('删除成功');
            history.go(0);
          }else{
            alert('删除失败');
            history.go(0);
          }
        }
    });
  })
</script>
